<?php

namespace app\api\controller;
use app\common\model\Feedback as FeedbackModel;
use app\common\controller\Api;
class Feedback extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /*
     * 意见反馈
     */
    public function submit()
    {
        $params = $this->request->post();

        if(mb_strlen($params['question'], 'utf8')>300){
            $this->error('反馈原因超出字数限制', mb_strlen($params['question'], 'utf8'));
        }

        $data = [
            'type' => xykeepFilterSql($params['feedback']),
            'content' => xykeepFilterSql($params['question']),
            'user_id' => $this->auth->id
        ];

        if(isset($params['job_order_id'])){
            $data['job_order_id'] = $params['job_order_id'];
        }

        $res = FeedbackModel::create($data);

        $message = array(
            'character_string2' => '1',
            'thing1' => '家教平台',
        );
        $res = \addons\weixin\library\WechatTemplateService::sendFastTemplate(
            'oNhI9vuKmri8OvHLHOd-rxasCn2k',//用户openid
            'rgae_FaeGj69Aqu-AEWGEYc_zzYYWaQlZH3Gv3qH6cU',//自定义模板编号
            $message,
            ''
        );

        $this->success('提交成功',$res);
    }
}